<?php

class urllink extends spController
{
  function __construct(){ // 公用
		parent::__construct(); // 这是必须的
		 require("lib/myextendClass/upload.php");
		 	   if(empty($_SESSION['xiaoq']['username']))
	   {
	      $this->error('您还没登录！',spUrl("main","index"));
	   }
	}

  function index(){
	  
	   $condation="id>0";
	   
	   $this->rows = spClass('link_list')->spPager($this->spArgs('page',1),50)->findAll('id>0','id desc');
	   $this->pager = spClass('link_list')->spPager()->getPager();
	   $this->display('aj/urllink_list.html');       
	   
	   }
  function addlink(){
	    
	   $this->display('aj/urllink_add.html'); 
	   
	  }
  function insert(){
	        
		$linkname=empty($_REQUEST['linkname'])?$this->error("链接名称不能为空"):$_REQUEST['linkname'];
		$linkurl=empty($_REQUEST['linkurl'])?$this->error("链接名称不能为空"):$_REQUEST['linkurl'];
	   // $qq=empty($_REQUEST['qq'])?'':$_REQUEST['qq'];
		$sort_id=empty($_REQUEST['sort_id'])?'':$_REQUEST['sort_id'];
		$is_open=empty($_REQUEST['is_open'])?'':$_REQUEST['is_open'];
		$upfile     = empty($_FILES['upfile']['name'])?"":$_FILES['upfile']['name'];   //产品封面图
		if(!empty($upfile)){
			$pic=upload('article','jpg,gif,rar,pdf',2048000000,1,'332*241',0);
		}
		$condation=array(
		    "linkname"=>$_REQUEST['linkname'],
			"linkurl"=>$_REQUEST['linkurl'],
			//"qq"=>$_REQUEST['qq'],
			"sort_id"=>$_REQUEST['sort_id'],
			"is_open"=>$_REQUEST['is_open'],
			'qq'     => $pic[0],
		);
	   if(spclass('link_list')->create($condation)){
		       $this->error('添加成功!',spUrl("urllink","index"));    
	    }
	   else
	   { 
	       $this->error("系统出现问题，请联系管理员!",spUrl("urllink","index"));
	    }
	  }
  function editlink(){
	  
	  $id=empty($_REQUEST['id'])?error('非法错误id'):$_REQUEST['id'];
	  $condation="id=".$id;
	  $this->row=spclass('link_list')->find($condation);
	  //print_r(row);die();
	  $this->display('aj/urllink_edit.html'); 
	  
	  }
  function update(){
	  $id=empty($_REQUEST['id'])?error('非法错误id'):$_REQUEST['id'];
	  $linkname=empty($_REQUEST['linkname'])?$this->error("链接名称不能为空"):$_REQUEST['linkname'];
	  $linkurl=empty($_REQUEST['linkurl'])?$this->error("链接名称不能为空"):$_REQUEST['linkurl'];
	 // $qq=empty($_REQUEST['qq'])?'':$_REQUEST['qq'];
	  $sort_id=empty($_REQUEST['sort_id'])?'':$_REQUEST['sort_id'];
	  $is_open=empty($_REQUEST['is_open'])?'':$_REQUEST['is_open'];
	  $upfile     = $_FILES['upfile']['name'];   //产品封面图
	  $condation="id=".$id;
	  $fied=array(
	         "linkname"=>$_REQUEST['linkname'],
			"linkurl"=>$_REQUEST['linkurl'],
			//"qq"=>$_REQUEST['qq'],
			"sort_id"=>$_REQUEST['sort_id'],
			"is_open"=>$_REQUEST['is_open'], 
	   );
	  if(!empty($upfile)){
			//删除更新前的图片
			$row=spClass('article_list')->find("id=".$id);
			unlink("uploads/article/".$row['upfile']);
			unlink("uploads/sm_article/".$row['upfile']);
			$pic=upload('article','jpg,gif,rar,pdf',2048000000,1,'332*241',0);
			$updaterow['qq']=$pic[0];
		}
	  $row=spclass('link_list')->update($condation,$fied);
	  if($row){
		$this->error('修改成功',spUrl("urllink","index"));  
	  }else
	  {
	   $this->error("系统出现问题，请联系管理员!",spUrl("urllink","index"));
	  }
	  
	  }
  function delete(){
	    $id=empty($_REQUEST['id'])?error('非法错误id'):$_REQUEST['id'];
		$condation="id=".$id;
		$row=spclass('link_list')->delete($condation);
		if($row){
		 $this->error('删去成功',spUrl("urllink","index"));  
	    }else
	    {
	     $this->error("系统出现问题，请联系管理员!",spUrl("urllink","index"));
	   }
	  
	  }

 }
?>